#include "Com.hpp"
#include <functional>
#include <memory>
#include <iostream>
#include "InetAddr.hpp"
#include "NetCal.hpp"
#include "Socket.hpp"
#include "TcpServer.hpp"
void Usage()
{
    std::cout << "./TcpServer server_port" << std::endl;
}

int main(int argc , char* args[])
{
    if(argc != 2)
    {
        Usage();
        return 2;
    }

    uint16_t port = std::stoi(args[1]);
    InetAddr server(port);
    Cal cal;
    
    std::unique_ptr<Protocol> pro = std::make_unique<Protocol>([&cal](Request& req){
           return  cal.Execute(req);
    });

    std::unique_ptr<TcpServer> tcpsvr = std::make_unique<TcpServer>(server.GetPort() , [&pro](std::shared_ptr<Socket> sock , InetAddr client){
            pro->GetRequest(sock , client);
    });

    tcpsvr->Start();
    
    return 0;
}